﻿<!DOCTYPE html>
<html lang="zh-cn">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
	<title>管理收货地址-个人中心-PHPMall</title>
	<meta name="Copyright" content="{$confRes.miaoshu}"/>
	<meta name="Keywords" content="{$confRes.sitename}"/>
	<meta name="Description" content="{$confRes.miaoshu}"/>
	<link rel="stylesheet" type="text/css" href="/static/index/css/pc-personal-address.39815a20.css">
	<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css">
	<script src="/static/layer/jquery.min.js"></script>
	<script src="/static/layer/layer.js"></script>
</head>
<body>

<div class="modal-content">
	<div class="modal-header">
		<h4 id="modalTitle" class="title">新增收货地址</h4>
		<i class="icon_close"></i>
	</div>
	<div class="modal-body">
		<form id="addressForm" class="add-address-form" novalidate="novalidate">
			<input type="hidden" id="addressId" name="id">

			<div class="row cf">
				<div class="meta">
					<label for="consName">收件人</label>
				</div>
				<div class="meta-value">
					<input type="text"id="name" name="cons_name" maxlength="8">
				</div>
			</div>
			<div class="row cf">
				<div class="meta">
					<label for="consPhone">手机号码</label>
				</div>
				<div class="meta-value">
					<input type="text" id="province" name="cons_phone" maxlength="11">
				</div>
			</div>
			<div class="row cf">
				<div class="meta">
					<label for="city-select">地区选择</label>
				</div>
				<div id="js_city-select" class="meta-value">

					<p id="area">
						<select name="city" id="city" class="second-level" >
							<option value="">请选择</option>
							{volist name='list_city' id='vo'}
							<option value="{$vo.region_id}">{$vo.region_name}</option>
							{/volist}
						</select>
						<select  id="country"  name="country" class="form-control level-Three">
							<option value="">请选择</option>
						</select>
						<select   id="detail" name="detail" class="form-control Three">
							<option value="">请选择</option>
						</select>
					</p>
				</div>
			</div>
			<div class="row cf">
				<div class="meta">
					<label for="consAddr">详细地址</label>
				</div>
				<div class="meta-value">
					<input type="text" id="detailed" name="cons_addr" maxlength="64">
				</div>
			</div>

		</form>
	</div>
	<div class="modal-footer">
		<div class="buttons">
			<button type="button" onclick="addAddress()"  class="btn btn-big btn-green btn-commit">确认</button>
		</div>
	</div>
</div>

<script>
    $(".second-level").change(function () {
        var region_id = $(this).val();
        var data = {"region_id":region_id};
        var url = "{:url('user/User/getlevelcity')}";
        $.post(url,data,function (reuslt) {
            var ax =eval(reuslt);
            var str="<option value=\"\">请选择</option>";
            for(var i=0;i<ax.length;i++){
                str+= "<option value="+ax[i]['region_id']+">"+ax[i]['region_name']+"</option>";
            }
            $(".level-Three").html(str);
            $(".Three").html('<option value="">请选择</option>');
        },'JSON')
    })

    $(".level-Three ").change(function () {
        var region_id = $(this).val();
        var data = {"region_id":region_id};
        var url = "{:url('user/User/getlevelcity')}";
        $.post(url,data,function (reuslt) {
            var ax =eval(reuslt);
            var str="<option value=\"\">请选择</option>";
            for(var i=0;i<ax.length;i++){
                str+= "<option value="+ax[i]['region_id']+">"+ax[i]['region_name']+"</option>";
            }
            $(".Three").html(str);
        },'JSON')
    });
    function addAddress() {
        var name = $("#name").val();
        var province = $("#province").val();
        var detailed = $("#detailed").val();
        var city = $("#city").val();
        var country = $("#country").val();
        var detail = $("#detail").val();
        if(name === ''){
            layer.msg('请输入收货人姓名');
            return;
        }
        if(province === ''){
            layer.msg('请输入电话号码');
            return;
        } if(detailed === ''){
            layer.msg('请输入详细地址');
            return;
        } if(city === ''){
            layer.msg('请选择省');
            return;
        } if(country === ''){
            layer.msg('请选择市');
            return;
        } if(detail === ''){
            layer.msg('请选择区');
            return;
        }
        $.ajax({
            url:"{:url('user/user/cheAddress')}",
            type:"POST",
            dataType:"json",
            data:{
                name:name,
                province:province,
                detailed:detailed,
                city:city,
                country:country,
                detail:detail,

            },
            success:function (res) {
                if(res.code === 1){
                    layer.alert('添加成功',function () {
                        window.parent.location.reload();  //刷新父级页面
                    });
                }
            }
        });

    }
</script>
